package net.gyapp.markim.core;

import net.gyapp.markim.core.entity.ConversationEntity;
import net.gyapp.markim.module.basic.event.AccountChanged;
import net.gyapp.markim.module.basic.event.AccountIml;

import org.greenrobot.eventbus.EventBus;
import org.jim.common.packets.ChatType;

/**
 * Author:  winds
 * Data:    2018/8/22
 * Version: 1.0
 * Desc:
 */


public class ImPrivateUtils {

    /**
     * 清除缓存
     *
     * @param conversationId
     */
    public static void clearCache(long conversationId) {
        ImHelper.deleteMessageEntity(conversationId);
        ImHelper.deleteConversationEntity(conversationId);
        EventBus.getDefault().post(new AccountChanged(AccountIml.ACCOUNT_CLEAR_CONVERSATION_CACHE));

    }


    public static void updateGroupName(ConversationEntity entity, String name, String avatar) {
        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            ImHelper.updateGroupEntity(entity.sessionIdStr, name, avatar);
        }
        ImHelper.updateConversationEntity(entity, name, avatar);
        EventBus.getDefault().post(new AccountChanged(AccountIml.ACCOUNT_CONTACT_INFO_CHANGED));
    }

    public static void updateUserName(ConversationEntity entity, String name, String avatar) {
        if (entity.chatType == ChatType.CHAT_TYPE_PRIVATE.getNumber()) {
            ImHelper.updateMemberEntity(entity.sessionIdStr, name, avatar);
        }
        ImHelper.updateConversationEntity(entity, name, avatar);
        EventBus.getDefault().post(new AccountChanged(AccountIml.ACCOUNT_CONTACT_INFO_CHANGED));
    }

    public static void clearSelfCache() {

    }
}
